<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * 每次活动详细信息逻辑
 */
class ActivityDetail extends LogicBase
{
    
    /**
     * 获取每次活动详细信息列表
     */
    public function getDetailList($where = [], $field = true, $order = '', $paginate = 0)
    {
        $this->modelActivityDetail->alias('ad');
        $join=[['my_activity a','ad.activity_id=a.id'],['my_healthroom h','a.room_id=h.room_id']];
        $field='ad.*, h.name as healthroom';
        return $this->modelActivityDetail->getList($where, $field, $order, $paginate,$join);
    }
    
    /**
     * 取得某个计划有关的详细活动记录
     * @param  [type] $activity_id [description]
     * @return [type]              [description]
     */
     public function getActivityDetailList($activity_id)
    {
        $this->modelActivityDetail->alias('a');
        $join=[['file f','f.id=a.file_id','left']];//加left
        $where=['a.activity_id'=>$activity_id];
        $field = "a.*,f.path as file_path";
        $order = '';
        $paginate = 0;
        return $this->modelActivityDetail->getList($where, $field, $order,$paginate,$join);
    }
    /**
     * 获取意见建议列表
     */
    
    public function getHealthroomSuggestionList()
    {
        $this->modelActivityDetail->alias('d');
        $county_id=session('department_info')['county_id'];
        $join=[['my_activity a','a.id=d.activity_id'],['my_healthroom h','h.room_id=a.room_id'],['region r','r.id=h.county_id']];
        if($county_id!=130400)
        {
           $where=['h.county_id'=>$county_id,'d.feedback'=>['neq','']];
        }else {
        $where=['d.feedback'=>['neq','']];
        }


        $field="d.*, h.name as healthroom, r.name as countyname";
        $order ='r.id,h.room_id';
        $paginate = 20;
        return $this->modelActivityDetail->getList($where, $field, $order,$paginate,$join);
    }

    /**
     * 每次活动详细信息信息编辑
     */
    public function activityDetailEdit($data = [])
    {
        $validate_result = $this->validateActivityDetail->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateActivityDetail->getError()];
        }
        
        $url = url('activityDetailManage',['activity_id'=>$data['activity_id']]);
        $data['intro'] = html_entity_decode($data['intro']);

        $result = $this->modelActivityDetail->setInfo($data);
        
        
        $result && action_log('编辑活动', '每次活动详细信息');
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelActivityDetiail->getError()];
    }
    /**
     * 每次活动详细信息信息编辑
     */
    public function activityDetailAdd($data = [])
    {
        
        $validate_result = $this->validateActivityDetail->scene('add')->check($data);

        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateActivityDetail->getError()];
        }
        
        $url = url('activityDetailManage',['activity_id'=>$data['activity_id']]);
        
        $result = $this->modelActivityDetail->setInfo($data);
        
      
        $result && action_log('活动增加=-', '每次活动详细信息');
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelActivityDetiail->getError()];
    }
    /**
     * 获取每次活动详细信息信息
     */
    public function getActivityDetailInfo($where = [], $field = true)
    {
        
        return $this->modelActivityDetail->getInfo($where, $field);
    }
    
    /**
     * 每次活动详细信息删除
     */
    public function activityDetailDel($where = [])
    {
        
        $result = $this->modelActivityDetail->deleteInfo($where);
        
        $result && action_log('删除', '每次活动详细信息删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelActivityDetail->getError()];
    }
}


